package com.young.android.common;

import java.util.Stack;

import android.app.Activity;

public class ScreenManager
{
  private static Stack<Activity> activityStack;
  private static ScreenManager instance;

  private ScreenManager()
  {

  }

  public static ScreenManager getScreenManager()
  {
    if (instance == null)
      instance = new ScreenManager();
    return instance;
  }

  // 退出栈顶Activity

  public void popActivity(Activity activity)
  {
    activity.finish();
    activityStack.remove(activity);
    activity = null;
  }

  // 获得当前栈顶Activity
  public Activity currentActivity()
  {
    return (Activity) activityStack.lastElement();
  }

  // 将当前Activity推入栈中
  public void pushActivity(Activity activity)
  {
    if (activityStack == null)
      activityStack = new Stack<Activity>();
    activityStack.add(activity);
  }

  // 退出栈中所有Activity
  public void popAllActivity()
  {
    while (!activityStack.empty())
    {
      Activity activity = currentActivity();
      popActivity(activity);
    }
  }

}
